package qf.index;//package com.qf.index;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.util.NumberUtil;
//import cn.hutool.db.Db;
//import cn.hutool.db.Entity;
//import cn.hutool.json.JSONUtil;
//import com.alibaba.fastjson.JSONObject;
//import lombok.Data;
//
//import java.io.Serializable;
//import java.sql.SQLException;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
//public class CheckHosp {
//
//    /**
//     * 这是一套检查的程序，用于检查规范的中国医院名称是否正确，以及是否规范，如果没有规范，会保存到checkHospSumTable中，人工添加规范后，再保存进unitsAndHospNameMap中，下次即可以使用了。
//     * 贾新志 2025.02.10
//     */
//    public static void main(String[] args) throws SQLException {
//        String newDataName = "scholar_25_01.";
//        String summaryTable = newDataName + "pm_ut_aid_info_0120";
//        String threeHospSumTable = newDataName + "three_hosp_sum";
//        String pmUtAidInfoTypeTable = newDataName + "pm_ut_aid_info_0120_type";
//        String chinaHospNameTable = newDataName + "tb_true_china_hosp_all_final";
//        String checkHospSumTable = newDataName + "check_hosp_sum";
//
/// /        Map<String, String> unitsAndHospNameMap = getUnitsAndHospNameMap(chinaHospNameTable, "id", "info`,`final", threeHospSumTable);
/// /        System.out.println("unitsAndHospNameMap.size(): " + unitsAndHospNameMap.size());
/// /        checkHosp(pmUtAidInfoTypeTable, "id", "type`,`unit", checkHospSumTable, unitsAndHospNameMap);
//
//        String s = "[{\"unitSumOrdinaryId\":31,\"coun\":\"日本\",\"cn\":\"京都大学医学院\",\"en\":\"kyoto university school medical\",\"abbr\":\"\",\"old\":\"\",\"exclude\":\"\",\"contain\":\"\",\"mustListList\":[[\"kyoto|京都大学\",\"\\\"kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university hospital\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of medicine\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university education\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university advance(d) science\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university school of public health\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university health service\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university katsura\\\"\"],[\"kyoto|京都大学\",\"\\\"京都大学\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto pref university medical\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university museum\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university gokasho\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university faculty of medicine\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school medical\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university foreign studies\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university school of medicine\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of pharmaceutical sciences\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university kyoto\\\"\"],[\"kyoto|京都大学\",\"\\\"aist kyoto university chemistry energy material open innovat laboratories\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of medicine and public health\\\"\"],[\"kyoto|京都大学\",\"\\\"aist kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university uji\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university arts\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university research reactor institute\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of agriculture\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university health services\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university yoshida\\\"\"],[\"kyoto|京都大学\",\"\\\"rims kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"wildlife research center of kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university yoshida honmachi\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of human health science\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto prefecture university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of medicine and school of public health\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine kyoto university kyoto japan\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university inuyama\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of medicine faculty of medicine\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university institute for advanced study\\\"\"],[\"kyoto|京都大学\",\"\\\"university of kyoto\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto universitykyoto\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university art & design\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university sakyo-ku\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university sakyo\\\"\"],[\"kyoto|京都大学\",\"\\\"kuias kyoto university\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university kitashirakawa oiwakecho\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university kitashirakawa\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of biostudies\\\"\"],[\"kyoto|京都大学\",\"\\\"aist-kyoto university chemical energy materials open innovation laboratory (chem-oil)\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of public health\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto univ\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university kurns\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university primate research institute\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university kitashirakawa-oiwakecho\\\"\"],[\"kyoto|京都大学\",\"\\\"kyoto university graduate school of medicine kyoto\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school medical\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"graduate school medical & publ health\\\"\"],[\"kyoto|京都大学\",\"\\\"school medical\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine and public health\\\"\"],[\"kyoto|京都大学\",\"\\\"school of public health in the graduate school of medicine\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine and faculty of medicine\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school of medicine and school of public health\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"postgrad medical school\\\"\"],[\"kyoto|京都大学\",\"\\\"graduate school medical publ health\\\"\"],[\"kyoto|京都大学\",\"\\\"school of medicine\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"graduate school medical science\\\"\"],[\"kyoto|京都大学\",\"\\\"inserm\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"postgrad school medical\\\"\"],[\"kyoto|京都大学\"],[\"kyoto|京都大学\",\"\\\"school medical & publ health\\\"\"],[\"kyoto|京都大学\",\"\\\"college of medical technology\\\"\"],[\"kyoto|京都大学\",\"\\\"crest\\\"\"],[\"kyoto|京都大学\",\"\\\"postgraduate school of medicine\\\"\"],[\"kyoto|京都大学\"]],\"excludeList\":[]}]";
//
//        List<SearchSaveInfo> enAuList = JSONObject.parseArray(s, SearchSaveInfo.class);
//        for (SearchSaveInfo searchSaveInfo : enAuList) {
//            System.out.println(searchSaveInfo);
//        }
//
//    }
//
//    @Data
//    public static class SearchSaveInfo implements Serializable {
//        private static final long serialVersionUID = 1L;
//        private int unitSumOrdinaryId = 0; // 表的自增主键，这里用来作为机构的唯一识别码，多个之间用|分隔
//        private String coun = "";
//        private String cn = "";
//        private String en = "";
//        private String abbr = "";
//        private String old = "";
//        private String url = "";   //单位官网url
//        private String alias = ""; //单位别名 多个以|隔开
//        private String exclude = ""; // 排除，可以多个以"|"隔开
//        private String contain = ""; // 包含，可以多个以"|"隔开
//        private List<List<String>> mustListList = new ArrayList<>(); // 这里是检索词的包含
//        private List<String> excludeList = new ArrayList<>(); // 这里是检索词的排除
//    }
//
//    public static void checkHosp(String pmUtAidInfoTypeTable, String autoId, String field, String checkHospSumTable, Map<String, String> unitsAndHospNameMap) throws SQLException {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + pmUtAidInfoTypeTable);
//        Map<String, Integer> unitAndSumMap = new HashMap<>();
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + pmUtAidInfoTypeTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + pmUtAidInfoTypeTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
////                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + pmUtAidInfoTypeTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    String type = entry.getStr("type");
//                    if ("1".equals(type)) {
//                        String unit = entry.getStr("unit");
//                        if (null != unit && unit.contains("\"}]")) {
//                            List<En.FourItems> unitList = JSONObject.parseArray(unit, En.FourItems.class);
//                            for (En.FourItems fourItems : unitList) {
//                                int size = fourItems.getAidList().size();
//                                unitAndSumMap.compute(fourItems.getName().toLowerCase(), (key, value) -> value != null ? (value + size) : size);
//                            }
//                        }
//                    }
//                }
//            }
//        }
//        Db.use().execute("truncate table " + checkHospSumTable);
//        unitAndSumMap.keySet().parallelStream().forEach(info -> {
//            String hosp = "";
//            String[] infoSplit = info.split("; ");
//            Set<String> resultSet = new HashSet<>();
//            if (unitsAndHospNameMap.containsKey(info)) {
//                hosp = unitsAndHospNameMap.get(info);
//            } else {
//                for (Map.Entry<String, String> entry : unitsAndHospNameMap.entrySet()) {
//                    String[] mapSplit = entry.getKey().split("; ");
//                    Set<String> set = new HashSet<>(Arrays.asList(mapSplit));
//                    boolean bool = true;
//                    for (String s : infoSplit) {
//                        if (!set.contains(s)) {
//                            bool = false;
//                            break;
//                        }
//                    }
//                    if (bool) {
//                        resultSet.add(entry.getKey() + "=" + entry.getValue());
//                    }
//                }
//                try {
//                    Db.use().insert(Entity.create(checkHospSumTable).set("info", info).set("h1", JSONUtil.toJsonStr(resultSet)).set("hosp", hosp).set("sum", unitAndSumMap.get(info)));
//                } catch (SQLException e) {
//                    e.printStackTrace();
//                }
//            }
//
//        });
//    }
//
//    public static Map<String, String> getUnitsAndHospNameMap(String chinaHospNameTable, String autoId, String field, String threeHospSumTable) throws SQLException {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int onePageNum = 1000;
//        List<Entity> tableNum = Db.use().query("select count(1) as count from " + chinaHospNameTable);
//        Map<String, Integer> unitAndSumMap = new HashMap<>();
//        Map<String, String> unitsAndHospNameMap = new HashMap<>();
////        Map<String, String> unitsAndHospNameMap = new HashMap<>();
//        if (tableNum.get(0).getInt("count") > 0) {
//            int tableMax = Db.use().queryNumber("select max(" + autoId + ") from " + chinaHospNameTable).intValue();
//            Collection<Integer> tableList = new ArrayList<>();
//            NumberUtil.appendRange(0, tableMax + onePageNum, onePageNum, tableList);
//            for (Integer startId : tableList) {
//                List<Entity> tableData = Db.use().query("select `" + autoId + "`,`" + field + "` from " + chinaHospNameTable + " where " + autoId + " between " + startId + " and " + (startId + onePageNum - 1));
////                System.out.println("\033[31;1m" + format.format(new Date()) + " 读表现在开始：" + startId + " 表名：" + chinaHospNameTable + Utils.printMemoryStr() + "\033[0m");
//                for (Entity entry : tableData) {
//                    String info = entry.getStr("info");
//                    String hosp = entry.getStr("final");
//                    if (null != info && null != hosp && info.contains("\"]") && hosp.length() > 3) {
//                        List<String> units = JSONObject.parseArray(info, String.class);
//                        Collections.sort(units);
//                        String unit = CollUtil.join(units, "; ").toLowerCase().trim();
//                        String l = units.get(0).toLowerCase().trim();
//                        boolean bool = l.contains("hosp ") || l.contains(" hosp") || l.contains("hospital") || l.contains("医院");
//                        unit = units.size() == 2 && bool ? (units.get(1) + "; " + l).toLowerCase().trim() : unit;
//                        unit = units.size() == 3 && bool ? (units.get(1) + "; " + units.get(2) + "; " + l).toLowerCase().trim() : unit;
//                        unitAndSumMap.compute(hosp + "|" + unit, (key, value) -> value != null ? (value + 1) : 1);
//                        unitsAndHospNameMap.put(unit, hosp);
//                    }
//                }
//            }
//        }
//        Db.use().execute("truncate table " + threeHospSumTable);
//        unitAndSumMap.keySet().parallelStream().forEach(info -> {
//            try {
//                Db.use().insert(Entity.create(threeHospSumTable).set("info", info).set("sum", unitAndSumMap.get(info)));
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//        });
//        return unitsAndHospNameMap;
//    }
//
//
//}
